package com.linpq.road.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.linpq.common.annotation.Log;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RdClimateEnvironment;
import com.linpq.road.service.RdClimateEnvironmentService;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.utils.poi.ExcelUtil;
import com.linpq.common.core.page.TableDataInfo;

/**
 * 气候环境Controller
 *
 * @author linpq
 * @date 2021-07-29
 */
@Controller
@RequestMapping("/road/climate_environment")
public class RdClimateEnvironmentController extends BaseController {
    private String prefix = "road/climate_environment";

    @Autowired
    private RdClimateEnvironmentService rdClimateEnvironmentService;

    @RequiresPermissions("road:climate_environment:view")
    @GetMapping()
    public String climate_environment() {
        return prefix + "/climate_environment";
    }

    /**
     * 查询气候环境列表
     */
    @RequiresPermissions("road:climate_environment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RdClimateEnvironment rdClimateEnvironment) {
        startPage();
        List<RdClimateEnvironment> list = rdClimateEnvironmentService.selectRdClimateEnvironmentList(rdClimateEnvironment);
        return getDataTable(list);
    }

    /**
     * 导出气候环境列表
     */
    @RequiresPermissions("road:climate_environment:export")
    @Log(title = "气候环境", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RdClimateEnvironment rdClimateEnvironment) {
        List<RdClimateEnvironment> list = rdClimateEnvironmentService.selectRdClimateEnvironmentList(rdClimateEnvironment);
        ExcelUtil<RdClimateEnvironment> util = new ExcelUtil<RdClimateEnvironment>(RdClimateEnvironment. class);
        return util.exportExcel(list, "climate_environment");
    }

    /**
     * 新增气候环境
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存气候环境
     */
    @RequiresPermissions("road:climate_environment:add")
    @Log(title = "气候环境", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RdClimateEnvironment rdClimateEnvironment) {
        return toAjax(rdClimateEnvironmentService.insertRdClimateEnvironment(rdClimateEnvironment));
    }

    /**
     * 修改气候环境
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        RdClimateEnvironment rdClimateEnvironment =rdClimateEnvironmentService.selectRdClimateEnvironmentById(id);
        mmap.put("rdClimateEnvironment", rdClimateEnvironment);
        return prefix + "/edit";
    }

    /**
     * 修改保存气候环境
     */
    @RequiresPermissions("road:climate_environment:edit")
    @Log(title = "气候环境", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RdClimateEnvironment rdClimateEnvironment) {
        return toAjax(rdClimateEnvironmentService.updateRdClimateEnvironment(rdClimateEnvironment));
    }

    /**
     * 删除气候环境
     */
    @RequiresPermissions("road:climate_environment:remove")
    @Log(title = "气候环境", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(rdClimateEnvironmentService.deleteRdClimateEnvironmentByIds(ids));
    }
}
